// pages/index/low_index/low_index.js
import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
import Dialog from "../../../miniprogram_npm/@vant/weapp/dialog/dialog"

const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "",
    //界面类型，从0开始
    type: 0,
    menuList: [
      //社区服务
      [
        {
          icon: "/common/image/icon_sqfw.png",
          title: "社区服务",
          method: "onCommunityService"
        },
        {
          icon: "/common/image/Icon1.png",
          title: "社区投票",
          method: "onVote"
        },
        {
          icon: "/common/image/icon_flfw.png",
          title: "法律服务",
          method: "onLawService"
        },
        {
          icon: "/common/image/home_spyy.png",
          title: "视频探视预约",
          method: "onVideoReserve"
        }
      ],
      //社区安全
      [
        {
          icon: "/common/image/home_aqxc.png",
          title: "安全宣传",
          method: "onSafetyPromotion"
        },
        {
          icon: "/common/image/home_aqtb.png",
          title: "安全大喇叭",
          method: "onSafetyBulletin"
        }
      ]
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      type: options.type == null || options.type == undefined ? 0 : parseInt(options.type)
    })
    let title = app.globalData.appTitle
    switch (this.data.type) {
      case 0:
        title = "社区服务"
        break
      case 1:
        title = "社区安全"
        break
    }
    this.setData({
      title: title
    })
    wx.setNavigationBarTitle({
      title: title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  /**
   * 社区服务
   */
  onCommunityService: function (e) {
    wx.navigateTo({
      url: "../community_service/community_service"
    })
  },

  /**
   * 社区投票
   * @param e
   */
  onVote: function (e) {
    app.isLogin("../vote/vote")
  },

  /**
   * 法律服务
   */
  onLawService: function (e) {
    app.isLogin("../law_service/law_service")
  },
  /**
   * 视频预约模块
   * @param e
   */
  onVideoReserve: function (e) {
    //判断是否登录
    if (app.globalData.userInfo != null) {
      if (app.globalData.userInfo.people_id != null) {
        wx.navigateTo({
          url: "../reserve/reserve?type=3"
        })
      } else {
        Dialog.confirm({
          title: '温馨提示',
          message: '暂未实名认证，请问是否前往进行实名认证？',
          confirmButtonText: "前往",
          cancelButtonText: "暂不"
        }).then(() => {
          // on confirm
          wx.navigateTo({
            url: '/pages/mine/room_register/room_register'
          })
        }).catch(() => {
          // on cancel
        });
      }
    } else {
      wx.navigateTo({
        url: '/pages/mine/login/login',
      })
    }
  },


  /**
   * 安全宣传
   * @param e
   */
  onSafetyPromotion: function (e) {
    wx.navigateTo({
      url: "../article/article?type=17"
    })
  },
  /**
   * 安全通报 （安全大喇叭）
   * @param e
   */
  onSafetyBulletin: function (e) {
    wx.navigateTo({
      url: "../article/article?type=18"
    })
  },
})